package com.syni.mdd.yhd.common.all.quartz.activity;

import com.syni.mdd.yhd.common.all.constants.Constants;
import com.syni.mdd.yhd.common.all.dao.jpa.record.CountUserRegisterDao;
import com.syni.mdd.yhd.common.all.entity.*;
import com.syni.mdd.yhd.common.all.entity.activity.CountBussinessActivity;
import com.syni.mdd.yhd.common.all.entity.activity.CountUserActivity;
import com.syni.mdd.yhd.common.all.entity.activity.CountUserRegister;
import com.syni.mdd.yhd.common.all.entity.coupon.BmsUserReceCoupon;
import com.syni.mdd.yhd.common.all.service.*;
import com.syni.mdd.yhd.common.all.service.record.CountBussinessActivityService;
import com.syni.mdd.yhd.common.all.service.record.CountUserActivityService;
import com.syni.mdd.sjb.common.component.utils.common.utils.ArithUtil;
import com.syni.mdd.sjb.common.component.utils.common.utils.DateTimeUtils;
import com.syni.mdd.yhd.common.all.utils.SpecificationUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @className BmsVideoQuartz
 * @description TOO
 * @Author cfx
 * @DATE 2019/7/26 16:15
 * @VERSION 1.0
 **/
@Component
@EnableScheduling
public class EatFiveMianOneActivityQuartz {
    private final Logger log = LoggerFactory.getLogger(getClass());

    @Autowired
    CountBussinessActivityService countBussinessActivityService;

    @Autowired
    CountUserActivityService countUserActivityService;

    @Autowired
    BmsUserReceCouponService bmsUserReceCouponService;

    @Autowired
    BmsBusinessService bmsBusinessService;

    @Autowired
    BmsUserService bmsUserService;

    @Autowired
    BmsDxClientRoleService bmsDxClientRoleService;

    @Autowired
    BmsDxOrderService bmsDxOrderService;

    @Autowired
    CountUserRegisterDao countUserRegisterDao;

    @Autowired
    BmsUserOperationLogService bmsUserOperationLogService;


    //@Scheduled(cron = "0 0 0/6 * * ?")  //每6小时统计一次
    //@Scheduled(cron = "0/5 * * * * ?")
    //@Scheduled(cron = "0 0 0 * * ?")  //每天晚上凌晨执行一次定时任务
    public void countBusinessActivityQuartz() {
        /*Date startTime = DateTimeUtils.converStringToDate("2019-11-29");
        Date endTime = DateTimeUtils.addDay(DateTimeUtils.converStringToDate("2019-12-01"),1);
        Map<String,Object> conditionMap = new LinkedHashMap<>();
        conditionMap.put("newTime_GTTE",startTime);
        conditionMap.put("newTime_LTT",endTime);
        List<BmsUser> bmsUsers = bmsUserService.getBaseDao().findAll(new SpecificationUtils(conditionMap));
        if(bmsUsers != null && bmsUsers.size() > 0) {
            List<CountUserRegister> countUserRegisters = new ArrayList<>();
            for(BmsUser bmsUser : bmsUsers) {
                Double total = bmsDxOrderService.countUserTotalConsum(bmsUser.getId());
                Integer num = bmsDxOrderService.countUserTotalNum(bmsUser.getId());
                CountUserRegister countUserRegister = new CountUserRegister();
                countUserRegister.setPhone(bmsUser.getPhone());
                countUserRegister.setRegisterTime(bmsUser.getNewTime());
                countUserRegister.setTotalNum(num);
                countUserRegister.setTotal(total);
                countUserRegister.setTotalBack(0d);
                //找出今天注册的逗留时长
                Integer userStay = bmsUserOperationLogService.countUserAppStay(bmsUser.getId(),startTime,endTime);
                countUserRegister.setAppStay(userStay);
                countUserRegisters.add(countUserRegister);
                //bmsDxOrderService.countBusinessOrderNum()
            }
            if(countUserRegisters.size() > 0){
                countUserRegisterDao.saveAll(countUserRegisters);
            }
        }*/
    }

}
